﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Vinno.Brand.Service.Migrations.BrandDb
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "MC_SYS");

            migrationBuilder.EnsureSchema(
                name: "VINNO_BR");

            migrationBuilder.CreateTable(
                name: "File",
                schema: "MC_SYS",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", maxLength: 128, nullable: false, comment: "编号"),
                    FileName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "文件名称"),
                    FileExtension = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false, comment: "文件扩展名"),
                    Size = table.Column<long>(type: "bigint", nullable: false, comment: "文件大小(bytes)"),
                    SerializedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "文件序列化名称"),
                    SHA1 = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "文件SHA1值"),
                    MD5 = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "文件MD5值"),
                    PhysicalPath = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false, comment: "物理存储路径"),
                    RequestPath = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true, comment: "文件请求路径"),
                    Version = table.Column<long>(type: "bigint", nullable: false, comment: "文件版本"),
                    CreatorId = table.Column<long>(type: "bigint", nullable: true, comment: "创建者编号"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpdaterId = table.Column<long>(type: "bigint", nullable: true, comment: "更新者编号"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_File", x => x.Id);
                },
                comment: "文件");

            migrationBuilder.CreateTable(
                name: "Saler",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    Name = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false, comment: "Name"),
                    Phone = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true, comment: "手机号"),
                    Email = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "邮箱"),
                    AreaCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true, comment: "区域代码"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Saler", x => x.Id);
                },
                comment: "省区经理");

            migrationBuilder.CreateTable(
                name: "Suggest",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    Name = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false, comment: "Name"),
                    Phone = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true, comment: "手机号"),
                    Email = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "邮箱"),
                    AreaCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true, comment: "省区代码"),
                    AreaCity = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true, comment: "地区名称"),
                    Company = table.Column<string>(type: "nvarchar(2048)", maxLength: 2048, nullable: true, comment: "公司/单位"),
                    Position = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true, comment: "职位"),
                    Type = table.Column<int>(type: "int", nullable: false, comment: "感兴趣的产品(Vinno.Brand.Pack.Data.ProductType：[0]台式；[1]便携；[2]掌上；[3]远程)"),
                    Requirement = table.Column<string>(type: "nvarchar(MAX)", maxLength: 4096, nullable: true, comment: "其他需求"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Suggest", x => x.Id);
                },
                comment: "反馈建议");

            migrationBuilder.CreateTable(
                name: "Product",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    Title = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false, comment: "Title"),
                    Description = table.Column<string>(type: "nvarchar(MAX)", maxLength: 4096, nullable: true, comment: "Description"),
                    TitleImgId = table.Column<long>(type: "bigint", nullable: false, comment: "标题图Id"),
                    VideoImgId = table.Column<long>(type: "bigint", nullable: false, comment: "产品宣传视频图链接"),
                    VideoUrl = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "产品宣传视频链接"),
                    Type = table.Column<int>(type: "int", nullable: false, comment: "Type(Vinno.Brand.Pack.Data.ProductType：[0]台式；[1]便携；[2]掌上；[3]远程)"),
                    IsNew = table.Column<bool>(type: "bit", nullable: false, comment: "IsNew"),
                    OrderNo = table.Column<int>(type: "int", nullable: true, comment: "排序号"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Product", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Product_TitleImgId",
                        column: x => x.TitleImgId,
                        principalSchema: "MC_SYS",
                        principalTable: "File",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Product_VideoImgId",
                        column: x => x.VideoImgId,
                        principalSchema: "MC_SYS",
                        principalTable: "File",
                        principalColumn: "Id");
                },
                comment: "产品信息");

            migrationBuilder.CreateTable(
                name: "ProductCarousel",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    ImgId = table.Column<long>(type: "bigint", nullable: false, comment: "缩略图Id"),
                    OrderNo = table.Column<int>(type: "int", nullable: false, comment: "排序号"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductCarousel", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProductCarousel_ImgId",
                        column: x => x.ImgId,
                        principalSchema: "MC_SYS",
                        principalTable: "File",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "产品矩阵轮播");

            migrationBuilder.CreateTable(
                name: "SpaceInfo",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    Title = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false, comment: "Title"),
                    SubTitle = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true, comment: "SubTitle"),
                    Url = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true, comment: "Url"),
                    ThumbImgId = table.Column<long>(type: "bigint", nullable: false, comment: "缩略图Id"),
                    Type = table.Column<int>(type: "int", nullable: false, comment: "Type(Vinno.Brand.Pack.Data.SpaceType：[0]高光时刻；[1]公益之星；[2]精彩案列)"),
                    OrderNo = table.Column<int>(type: "int", nullable: false, comment: "排序号"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SpaceInfo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SpaceInfo_ThumbImgId",
                        column: x => x.ThumbImgId,
                        principalSchema: "MC_SYS",
                        principalTable: "File",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "品牌空间资讯");

            migrationBuilder.CreateTable(
                name: "ProductCase",
                schema: "VINNO_BR",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", maxLength: 128, nullable: false, comment: "编号"),
                    CaseImgId = table.Column<long>(type: "bigint", nullable: false, comment: "案列图Id"),
                    CaseDesc = table.Column<string>(type: "nvarchar(MAX)", maxLength: 4096, nullable: true, comment: "案列描述"),
                    ProductId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "产品Id"),
                    OrderNo = table.Column<int>(type: "int", nullable: true, comment: "排序号"),
                    CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductCase", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProductCase_CaseImgId",
                        column: x => x.CaseImgId,
                        principalSchema: "MC_SYS",
                        principalTable: "File",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ProductCase_ProductId",
                        column: x => x.ProductId,
                        principalSchema: "VINNO_BR",
                        principalTable: "Product",
                        principalColumn: "Id");
                },
                comment: "产品案列");

            migrationBuilder.CreateIndex(
                name: "IX_Product_TitleImgId",
                schema: "VINNO_BR",
                table: "Product",
                column: "TitleImgId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Product_Type",
                schema: "VINNO_BR",
                table: "Product",
                column: "Type");

            migrationBuilder.CreateIndex(
                name: "IX_Product_VideoImgId",
                schema: "VINNO_BR",
                table: "Product",
                column: "VideoImgId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ProductCarousel_ImgId",
                schema: "VINNO_BR",
                table: "ProductCarousel",
                column: "ImgId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ProductCase_CaseImgId",
                schema: "VINNO_BR",
                table: "ProductCase",
                column: "CaseImgId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ProductCase_ProductId",
                schema: "VINNO_BR",
                table: "ProductCase",
                column: "ProductId");

            migrationBuilder.CreateIndex(
                name: "IDX_Saler_AreaCodeName",
                schema: "VINNO_BR",
                table: "Saler",
                columns: new[] { "AreaCode", "Name" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SpaceInfo_ThumbImgId",
                schema: "VINNO_BR",
                table: "SpaceInfo",
                column: "ThumbImgId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SpaceInfo_Type",
                schema: "VINNO_BR",
                table: "SpaceInfo",
                column: "Type");

            migrationBuilder.CreateIndex(
                name: "IX_Suggest_AreaCode",
                schema: "VINNO_BR",
                table: "Suggest",
                columns: new[] { "AreaCode", "Type" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ProductCarousel",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "ProductCase",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "Saler",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "SpaceInfo",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "Suggest",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "Product",
                schema: "VINNO_BR");

            migrationBuilder.DropTable(
                name: "File",
                schema: "MC_SYS");
        }
    }
}
